﻿Imports DTO
Imports System.Data.Linq

Public Class TheThuVienDao
    Public Shared Function LayBang() As Table(Of TheThuVien)
        Dim db As New ThuVienDataContext()
        Return From ttv In db.TheThuViens Where ttv.Da_huy = False Select ttv
    End Function

    Public Shared Function LayDanhSach() As IEnumerable(Of TheThuVien)
        Dim lst As IEnumerable(Of TheThuVien)
        Dim db As New ThuVienDataContext()
        lst = From ttv In db.TheThuViens Where ttv.Da_huy = False Select ttv
        Return lst
    End Function

    Public Shared Function LayThe(ByVal m As Integer) As TheThuVien
        Dim db As New ThuVienDataContext()
        Dim lst = From ttv In db.TheThuViens Where ttv.MT = m Select ttv
        Dim the As New TheThuVien

        If lst.Count > 0 Then
            the = lst.Single
        Else
            the.MT = -1
        End If

        Return the
    End Function

    Public Shared Sub Them(ByVal t As TheThuVien)
        Dim db As New ThuVienDataContext()
        db.TheThuViens.InsertOnSubmit(t)
        db.SubmitChanges()
    End Sub

    Public Shared Sub CapNhat(ByVal the As TheThuVien)
        Dim db As New ThuVienDataContext()
        Dim ttv = (From t In db.TheThuViens Where t.MT = the.MT Select t).Single

        ttv.Ngay_lap_the = the.Ngay_lap_the
        ttv.Ngay_het_han = the.Ngay_het_han
        ttv.Da_huy = the.Da_huy

        db.SubmitChanges()
    End Sub

    Public Shared Sub Xoa(ByVal m As Integer)
        Dim db As New ThuVienDataContext
        Dim ttv = (From t In db.TheThuViens Where t.MT = m Select t).Single
        ttv.Da_huy = True
        db.SubmitChanges()
    End Sub
End Class
